// 导入auth模块
import { getToken } from '@/utils/auth'

// 登录功能，只需要存储 token 即可，所以，状态默认值为：''
const initialState = {
    token: getToken(),
    name: ''
}

const user = (state = initialState, action) => {
    switch(action.type) {
        case 'user/setToken':
            return {
                ...state,
                token: action.payload
            }
        case 'user/setName':
            return {
                ...state,
                name: action.payload
            }
        default:
            return state
    }
}

export default user